home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / INFO / DOSTIPS.ZIP / DOSTIPS1.TXT next >
Text File  |  1987-12-14  |  13KB  |  228 lines

  1.                            MS-DOS_Tips
  2.  
  3.  
  4. Hi Folks!
  5.  
  6. I'd  like to share some of my time-saving tips in MS-DOS.   Since 
  7. being  introduced  to the operating system some  time  ago,  I've 
  8. spent  many hours attempting to develop ways to save  time  while 
  9. programming.   Programming  involves the use  of  every  resource 
  10. available from your PC.  When I refer to "PC" I am addressing any 
  11. MS/PC-DOS  compatible computer.  The Public Domain has to be  the 
  12. most informative source of ideas I have ever come across.  I will 
  13. have to admit that 50% of my programming conceptions originate in 
  14. the PD.  I contribute to the PD as much as the next guy so I feel 
  15. using  the  resource  is  permissible.   My  point  is  that  for 
  16. information and examples to follow, the PD is the place to  look.  
  17. The electronic bulletin board network is the best source for  PD.  
  18. With  the low cost of modems and the availability  of  incredibly 
  19. feature-packed  modem programs in the PD (read: free), I  see  no 
  20. reason not to plug in to the resource gold mine.  Unless you only 
  21. occasionally  use your PC for applications programs only,  GET  A 
  22. MODEM!
  23.  
  24. Throughout this article I will refer to MS-DOS synonymously  with 
  25. PC-DOS.   Also, all references are to my Kaypro 286i system.   My 
  26. drives  are  configured  as follows.  A and B  are  1.2  megabyte 
  27. floppies.   C  and D are 21.5 megabyte hard disks.  Some  of  the 
  28. procedures  outlined  below may not be suitable for  360K  floppy 
  29. based  systems.  I do also use all the procedures outlined  below 
  30. on my Kaypro 16.  A and B are 360K floppies.  C is a 10  megabyte 
  31. hard  disk.   I think the Kaypro 16 is the most  popular  of  the 
  32. pseudo-16 bit Kaypro systems so the procedures will apply to it.
  33.  
  34. MS-DOS has this great built-in facility called batch  processing.  
  35. In the old days (two years ago?) batch processing referred to the 
  36. use  of a main-frame computer in slices of time.   All  processes 
  37. needing CPU time were bundled together on punch cards and all fed 
  38. in  at  one time.  They were  sequentially  processed  generating 
  39. corresponding  output  or files and then the next member  of  the 
  40. batch was processed.  There was no benefit of interactive use  of 
  41. the  computer.   You had one chance to get it right or  else  you 
  42. resubmitted  the  whole  batch  again the  next  day.   With  the 
  43. introduction of the personal computer, interactive utilization of 
  44. the  machine is possible.  But with all this technology, we  find 
  45. ourselves in redundancy sometimes.  There is a way out.
  46.  
  47. Many sequences of commands are used daily by the operator in  MS-
  48. DOS  that can be batched together.  There are two simple ways  to 
  49. create  a batch file.  One is to use a text editor.  I use  EDLIN 
  50. just  because of it's simple command set and small size and  fast 
  51. speed.  Believe me, it's not much of an editor for anything  more 
  52. than  that.  The other way is by device redirection.   Here's  an 
  53. example:
  54.      C:
  55.      CD \FRED
  56.      MARTHA
  57.  
  58. If  you  entered  this  list  of  commands  into  a  file  called 
  59. HARRY.BAT, every time you typed HARRY at the DOS command  prompt, 
  60. the  COMMAND.COM  resident  processing  system  would  read   the 
  61. commands  from this file one line at a time.  First we would  log 
  62. into  drive C.  Then change to the directory on that drive  named 
  63. FRED.   Now the system would run a program named MARTHA.  If  you 
  64. include  a program name after MARTHA, then as soon as  MARTHA  is 
  65. through  running,  the COMMAND.COM processor remembers  you  have 
  66. another command to execute and will do just that.  You can string 
  67. these  things out as far as you want.  In fact, you can  use  the 
  68. COMMAND /C command to load another COMMAND.COM processor and  use 
  69. the DOS commands in it just like before.  Now as soon as you type 
  70. EXIT at the DOS prompt, the first COMMAND.COM processor will take 
  71. over  and  execute  the remaining commands.   I'll  give  you  an 
  72. example:
  73.      C:
  74.      CD \FRED
  75.      MARTHA
  76.      COMMAND /C
  77.      WP
  78.  
  79. Suppose  you  have  a file called DO-IT.BAT  on  your  disk.   It 
  80. contains  the list of commands shown above.  Typing DO-IT at  the 
  81. DOS prompt will log into drive C, change directory to FRED, run a 
  82. program  called  MARTHA and as soon as MARTHA  was  finished  you 
  83. would  see a DOS prompt.  You are not really where  you  started.  
  84. You  are  now  within a second DOS command  processor.   You  can 
  85. execute  any DOS command you want.  Now as soon as you  type  the 
  86. command EXIT, you are returned to the first command processor and 
  87. it  will pick up where it left off, executing the program  called 
  88. WP.  This was a case of "nesting" the command processor.  In CP/M 
  89. the equivalent of the command processor is called the CCP.   ZCPR 
  90. was  a great attempt to help the user in CP/M to accomplish  some 
  91. of the tasks available in DOS.
  92.  
  93. The  second  method of generating a batch file is  called  device 
  94. redirection.  It's really a quite fast economical way to generate 
  95. any  small file.  DOS treats everything it is connected to  as  a 
  96. device.  The CRT, keyboard, disk drives, serial port etc. are all 
  97. devices to DOS.  You have the ability to copy files, or  actually 
  98. any data string, to and from the different devices.  You probably 
  99. already know that any time you append a ">PRN" to a command,  all 
  100. output  from the command is redirected to the printer.   You  can 
  101. redirect  to  a file also.  ">FRED" appended to a  command  would 
  102. send  all output from the command to a file called FRED.  If  you 
  103. want to add (append) stuff to the end of an already existing file 
  104. just use two ">"'s.  As in TYPE FILENAME.EXT >>FRED.  This  would 
  105. send all printable characters sent to the screen to the end of an 
  106. existing file named FRED.  These examples of I/O redirection  are 
  107. fairly  popular and documented.  One type of redirection  is  all 
  108. too  often  ignored.  COPY CON is a form of redirection  that  is 
  109. handy  in  creating  small batch files.  If you  type  "COPY  CON 
  110. FRED.BAT"  all  keys typed on the keyboard and generated  on  the 
  111. screen  will  be  sent to a file named FRED.BAT.   You  have  now 
  112. created  a batch file.  The return key will generate  a  carriage 
  113. return  character in the file.  To end the redirection and  close 
  114. the file use the end-of-file character CTRL-Z.  You can hold down 
  115. the  CTRL  key  or use the F6 function  key.   Actually  all  the 
  116. command accomplished was the copying of one devices output  (CON) 
  117. to  another  device. (in this case the other device  was  a  file 
  118. named FRED) (Is that anything like a boy named Sue?)
  119.  
  120. DOS users will tell you that there is one thing batch files  will 
  121. not accomplish; the ability to run another batch file, then after 
  122. it is finished, return to the originating batch file to  continue 
  123. processing.  AHA!  Not true.  You can execute another batch  file 
  124. as a "subroutine".  A subroutine, as defined in the Mike Stickney 
  125. Fanatic Programmer's Manual, is a procedure, function or complete 
  126. program called from another procedure, function or program; after 
  127. which  a  return is made to the calling  procedure,  function  or 
  128. program.  In other words, do something and come back when  you're 
  129. finished.   If you use the COMMAND /C with a batch filename,  DOS 
  130. will  load another command processor, execute the batch file  and 
  131. as  long as the batch file has an EXIT command in it,  return  to 
  132. the  point in the originating batch file after the  last  command 
  133. issued.   The  syntax  (no, not a tax on sex,  but  the  required 
  134. spelling,  etc.) of the command is "COMMAND command  /C".   Where 
  135. "command" is any DOS command or batch filename.  Just remember to 
  136. put the EXIT command in the called batch file.
  137.  
  138. Here's  a tricky one.  Have you ever wanted to have a batch  file 
  139. go  to  another  directory, issue a command, and  return  to  the 
  140. directory  area that it was called from?  Sure, you could  put  a 
  141. "CD  \directory"  command  at the end of the  batch  file.   What 
  142. happens when you call this batch file from another directory?  If 
  143. your path is set properly, IE: multiple paths of which one points 
  144. to the directory area where all your batch files are stored,  you 
  145. can  call  your batch files from ANYWHERE in ANY disk  drive.   I 
  146. figured out a way to accomplish a return to the calling directory 
  147. area.   (I'll  admit I saw an article in the latest  PC  magazine 
  148. that accomplishes this in a manner similar to mine, but I figured 
  149. out  mine first!)  First I'll list the batch commands below  that 
  150. accomplish this.  The commands are in a file named SAVDIR.BAT.
  151.  
  152.      DEL C:\BAT\RETDIR.BAT >NUL
  153.      COPY C:\BAT\CD.TXT C:\BAT\RETDIR.BAT >NUL
  154.      CD >>C:\BAT\RETDIR.BAT
  155.      EXIT
  156.  
  157. This  list assumes a file already exists in C:\BAT named  CD.TXT.  
  158. CD.TXT contains the characters "CD ".  I have my directory search 
  159. path set up as follows:
  160.  
  161.      PATH=C:\DOS;C:\BAT;C:\;C:\NORTON;C:\UTILITY;C:\WP;D:\MOUSE
  162.  
  163. As  you can see, I have a path set to my C drive \BAT  directory.  
  164. My \BAT directory contains all my batch files.  This way whenever 
  165. I  need a batch file I need only type the batch command  name  at 
  166. the  prompt.  DOS will search along the paths for  the  directory 
  167. containing  the batch file.  This might get a little  complex  so 
  168. please read this a few times until you understand it.  
  169.  
  170. The only other thing you need is the awareness that when you want 
  171. the batch file to return to the calling directory area, you issue 
  172. the  command RETDIR.  Now I'll outline what all this  mess  does.  
  173. This  refers  to  the four line batch  file  listed  above  named 
  174. SAVDIR.BAT.
  175.  
  176. Line  1)  Delete any file in the \BAT directory on  the  C  drive 
  177. named  RETDIR.BAT.  This gets rid of any RETDIR batch  file  left 
  178. over from the last use.
  179.  
  180. Line  2)  Copy  the contents of CD.TXT ("CD ") to  a  file  named 
  181. RETDIR.BAT.   The  >NUL on the end sends all output  to  the  NUL 
  182. device.   The  NUL device is just like it  sounds,  meaning  send 
  183. output to never-never land.  In other words, don't clutter up the 
  184. screen with crap when you don't have to.  Otherwise you'll see "1 
  185. file(s) copied" and this might be confusing.
  186.  
  187. Line  3) Issue a CD command and append the output to the file  we 
  188. created above.  Issuing CD by itself will cause DOS to print  out 
  189. the curent disk and directory.  Since we redirected the output to 
  190. the  RETDIR.BAT file, now we have a command in a batch file  that 
  191. will take us back to where we originated.  All references to  the 
  192. files  have  their full paths preceding them so  the  files  will 
  193. always  be found in the same place.  The issuance of the  command 
  194. "RETDIR"  will  cause the RETDIR.BAT file to  be  executed  which 
  195. contains the command we need.
  196.  
  197. Line 4) EXIT back to the originating command processor.
  198.  
  199. The  only  thing you need be aware of at this point is  that  the 
  200. SAVDIR   command  must  be  executed  as  a  child   process   of 
  201. COMMAND.COM.   In  other  words  we need to  run  SAVDIR  like  a 
  202. subroutine  so  that when the SAVDIR batch file is done,  we  are 
  203. returned  to the originating batch file that has the commands  we 
  204. needed to process in the first place.  This is done as  described 
  205. earlier.  "COMMAND SAVDIR /C".  I have found one limitation  with 
  206. this process.  It will not change the logged disk drive.  If  you 
  207. call  this  procedure  from  drive D and  the  commands  you  are 
  208. executing  take you to drive C, you will remain in drive C.   Now 
  209. the SAVDIR/RETDIR stuff hasn't completely been wasted.   Whenever 
  210. you  issue the CD command specifying a different disk drive,  the 
  211. "default"  directory  on the drive will be changed  to  what  you 
  212. specify.   Remember, when you type CD all by itself  DOS  outputs 
  213. the drive and directory presently occupied.  Since we use the  CD 
  214. command to generate our RETDIR batch file, the command  generated 
  215. will  contain the disk drive prefix.  If all our  batch  commands 
  216. keep  us  in the same drive, we're okay.   Changing  the  default 
  217. directory of the drive you are presently logged into is the  same 
  218. as logging into that directory.  If you do use this procedure  to 
  219. migrate  from drive to drive, all you have to do after the  batch 
  220. file  is done is change drives.  The originating  directory  area 
  221. will be the one you are automatically dropped into.
  222.  
  223. As  you can see, you can make batch file processing as simple  or 
  224. as  complex as you want.  With all the commands available to  you 
  225. at  the  DOS  prompt, you really have  a  whole  new  programming 
  226. language suitable for minor housekeeping chores.
  227.  
  228.                                       Mike Stickney, SYSOP - SKUG